package com.raja.servingStation.controller;

import com.raja.servingStation.service.TestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by dell on 2017/3/21.
 */
@Controller
public class TestController {
    private static final Logger log = LoggerFactory.getLogger(TestController.class);

    @Autowired
    TestService testService;

    @RequestMapping(value = "/system/user")
    public void getUser(HttpServletResponse response){
        try {
            testService.select();
            response.getWriter().write("55555555555555");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @RequestMapping("/send")
    public void send(HttpServletResponse response){

        try {
            response.getWriter().write("ok");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @RequestMapping(value = "insert")
    public void weilcome(HttpServletRequest request ,HttpServletResponse response){
        try {
            testService.save();
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
    }

    /** demo
     *
     * 获取车辆，包含转发的状态的
     * @param request
     * @param response
     * @return
     */
//    @RequestMapping(value = "/car/getRelayCars",method = RequestMethod.GET)
//    public ResponseEntity getRelayCar(HttpServletRequest request, HttpServletResponse response){
//        try {
//            JSONObject headerJson = RequestUtil.parseHeader(request);
//            JSONObject body = RequestUtil.parseBody(request);
////            String keyValue = body.getString("keyValue");
////            Integer isSendGp = body.getInteger("isSendGp");
//            Integer currPage = body.getInteger("currPage");
////            Integer pageSize = body.getInteger("pageSize");
//            if(currPage == null)
//                return responseUtil.exception(ReturnCodes.ERR_param_ERROR);
//            String param =  pjCarsParam(headerJson,body);
//            String json = carInfoService.getRelayCars(web_api_url+Constants.car_relay_url,param);
//            JSONObject jsonObject = JSON.parseObject(json);
//            return responseUtil.success(jsonObject.getJSONObject("data"),headerJson.getInteger("userId"));
//        }catch (Exception e){
//            log.error(e.getMessage(),e);
//            return responseUtil.exception(ReturnCodes.REQUEST_EXCEPTION);
//        }
//    }

}
